package com.gyul.findmystock.ui.home;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v13.app.FragmentTabHost;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gyul.findmystock.R;
import com.gyul.findmystock.entity.CompanyEntity;
import com.gyul.findmystock.util.Utils;

public class HomeActivity extends Activity {
    
	private FragmentTabHost mTabHost;
	
    CompanyEntity selectedCompany;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        requestWindowFeature(Window.FEATURE_NO_TITLE | Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.activity_home);
                
        final ActionBar actionBar = getActionBar();
        
        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup(this, getFragmentManager(), R.id.home_tabcontent);

		String title = Utils.getResourceString(R.string.title_stock_view);
		mTabHost.addTab(mTabHost.newTabSpec(title).setIndicator(title),
				FragmentStockView.class, null);
		
		title = Utils.getResourceString(R.string.title_stock_trade);
		mTabHost.addTab(mTabHost.newTabSpec(title)
				.setIndicator(title), FragmentStockTrade.class, null);

		title = Utils.getResourceString(R.string.title_stock_add);
		mTabHost.addTab(mTabHost.newTabSpec(title)
				.setIndicator(title), FragmentStockAdd.class, null);
		
		title = Utils.getResourceString(R.string.title_stock_option);
		mTabHost.addTab(mTabHost.newTabSpec(title)
				.setIndicator(title), FragmentStockOption.class, null);
		
		int tabCount = mTabHost.getTabWidget().getTabCount();
		for (int i = 0; i < tabCount; i++) {
		    final View view = mTabHost.getTabWidget().getChildTabViewAt(i);
		    if ( view != null ) {
		        // reduce height of the tab

		        //  get title text view
		        final View textView = view.findViewById(android.R.id.title);
		        if ( textView instanceof TextView ) {
		            // just in case check the type

		            // center text
		            ((TextView) textView).setGravity(Gravity.CENTER);
		            // wrap text
		            ((TextView) textView).setSingleLine(false);

		            // explicitly set layout parameters
		            textView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
		            textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
		        }
		    }
		}
    }   
}
